package com.bbx.taxi.client.Adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bbx.api.sdk.model.passanger.Return.Coupon.Coupons;
import com.bbx.taxi.official.R;
import com.bbx.taxi.client.Activity.Address.AddAddressActivity;
import com.bbx.taxi.client.Activity.Menu.SetActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 可用优惠劵
 */
public class OrderTypeAdapter extends BaseAdapter {
	private List<String> list;
	private Activity main;
	  public  Map<Integer, Boolean> isSelected; 
	public OrderTypeAdapter(Activity context,List<String> list) {
		this.list=list;
	   main=context;
	   init();  
	}
	 //初始化    
    private void init() {   
        //这儿定义isSelected这个map是记录每个listitem的状态，初始状态全部为false。    
        isSelected = new HashMap<Integer, Boolean>();    
        for (int i = 0; i < list.size(); i++) {    
            isSelected.put(i, false);    
        }    
    }    
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
		
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewOrderTypeHolder viewholder;
		if(convertView==null){      
		LayoutInflater inflater=LayoutInflater.from(main);
		convertView=(View)inflater.inflate(R.layout.item_available,null);        
		viewholder=new ViewOrderTypeHolder();
		viewholder.text=(TextView)convertView.findViewById(R.id.tv_available);	
		viewholder.checkbox=(CheckBox)convertView.findViewById(R.id.cb_available);	
		convertView.setTag(viewholder);	
		}
		else viewholder=(ViewOrderTypeHolder)convertView.getTag();
		viewholder.text.setText(list.get(position));
		viewholder.checkbox.setChecked(isSelected.get(position)); 
		return convertView;
		
}
	public class ViewOrderTypeHolder{                   
		TextView text;
		public CheckBox checkbox;
	}
}
